//
//  FKHttpNetWork.swift
//  FireKnowledge
//
//  Created by 杨伟毅 on 2019/4/20.
//  Copyright © 2019 wely. All rights reserved.
//

import Foundation
import Alamofire

typealias completionBlock = (DataResponse<Any>) ->Void

class FKHttpNetWork: NSObject {
    static let shared = FKHttpNetWork()
    let headers: HTTPHeaders = [
        "Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==",
        "Accept": "application/json",
    ]
}

extension FKHttpNetWork {
    fileprivate func alomofirePost(_ postUrl:URLConvertible , parameters:Parameters,method:HTTPMethod,completionHandler: @escaping completionBlock){
        switch method {
        case .post:
            
            Alamofire.request(postUrl, method : .post , parameters : parameters,headers: headers).responseJSON { response  in
                completionHandler(response)
            }
            break
        case .get:
            Alamofire.request(postUrl, method : .get ,headers: [:]).responseJSON { response  in
                completionHandler(response)
            }
            break
        default:
            break
        }
    }
    
    class  func postRequest(_ postUrl:URLConvertible , parameters:Parameters,method:HTTPMethod,completionHandler: @escaping completionBlock){
        shared.alomofirePost(postUrl, parameters: parameters, method: method, completionHandler: completionHandler)
    }
    
}
